import React, { useState, useEffect } from 'react';
import '../MemberGrade/MemberGrade.css'
import axios from '../../../utils/myAixos.js'
import { Button, Table, Space } from 'antd';
import { useNavigate } from 'react-router-dom'

const MemberGrade = () => {
    const columns = [
        {
            title: '等级名称',
            dataIndex: 'm_carname',
            key: '1',
            align: 'center',
        },
        {
            title: '默认会员等级',
            dataIndex: 'm_dengji',
            key: '2',
            align: 'center',
        },
        {
            title: '会员老师',
            dataIndex: 'm_teacher',
            key: '3',
            align: 'center',

        },
        {
            title: '会员积分',
            dataIndex: 'm_jifen',
            key: '4',
            align: 'center',

        },
        {
            title: '折扣',
            dataIndex: 'm_zhekou',
            key: '5',
            align: 'center',

        },
        {
            title: '操作',
            dataIndex: 'm_caozuo',
            key: '6',
            align: 'center',
            render: (_, record) => (
                <Space size="middle">
                    <a type="primary" onClick={() => Edit(record)}>编辑</a>
                </Space>
            ),
        },

    ];
    //跳转
    const navigate = useNavigate()
    // 编辑
    const Edit = (row) => {
        console.log('确定编辑按钮', row.m_carname)
        navigate('/HomePage/EditMemberGrade', {
            state: {
                m_carname: row.m_carname,
                m_jifen: row.m_jifen,
                m_zhekou: row.m_zhekou
            }
        })
    }
    const Add = () => {
        console.log('确定编辑按钮')
        navigate('/HomePage/AddMemberGrade')
    }
    const [dataList, setDataList] = useState([]); //表格数据
    //获取会员数据
    const getStu = () => {
        axios({
            url: '/getCarData',
            method: 'post'
        }).then(res => {
            console.log('获取所有会员数据1', res.data.data)
            console.log(res.status)
            if (res.status === 200) {
                setDataList(res.data.data)
            }
        }).catch(err => {
            console.log('获取所有会员数据2', err)
        })
    }
    //1、获取到所有会员卡的数据
    useEffect(() => {
        getStu()
    }, [])
    return (
        <div class="boxMemberGrade">
            {/* 按钮栏 */}
            <div class="titleGrade">
                <Button type="primary" onClick={() => Add()}>添加等级</Button>
            </div>
            {/* 表单 */}
            <div class="bodyMemberGrade">
                <Table rowKey={record => record.m_id} columns={columns} dataSource={dataList} />
            </div>
        </div>
    )
}
export default MemberGrade